//
//  TheCountdown.m
//  QWEQWEQWEQWEQE
//
//  Created by 杨元龙 on 14-11-22.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TheCountdown.h"


@implementation TheCountdown


+(NSString *)theCountWith:(NSString *)date
{
    
   
    
    NSDate *now = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags =NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
    NSInteger year = [dateComponent year];
    NSInteger month = [dateComponent month];
    NSInteger day = [dateComponent day];
    
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM月dd日"];
    
    NSString *da = [date substringWithRange:NSMakeRange(5, 6)];
    
    NSDate *date1 = [formatter dateFromString:da];
    
    NSDate *date2 = [formatter dateFromString:[NSString stringWithFormat:@"%ld月%ld日",(long)month, (long)day]];
    NSTimeInterval aTimer = [date1 timeIntervalSinceDate:date2];
    
    
    int day1;
    if (aTimer<0) {
        
        if ((0 == year % 4 && 0 != year % 100) || (0 == year % 400 ) ) {
            day1= (int)(aTimer/3600/24) + 365;
        } else {
            day1 = (int)(aTimer/3600/24) + 366;
        }
        
    }else
    {
        day1 = (int)(aTimer/3600/24);
    }
    
    NSString *dural = [NSString stringWithFormat:@"%d天", day1];
    
    return dural;
    
    
}

@end
